﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
/// 站点终端页面的基类
/// </summary>
public class SitePageBase : Shove.Web.UI.ShoveWebPartBasePage
{
    public Site _Site = null;

    public bool isRequestLogin = false;                 // 是否需要登录
    public bool isFramePage = false;                    // 是否框架内的页面。如果是框架内的页面，转跳登录将在 _top 进行。    

    public bool isCompulsoryNoAllowDesign = false;      // 是否强制不允许进入设计状态

    public SitePageBase()
    {
    }

    protected override void SetSiteID()
    {
        if (_Site == null)
        {
            throw new Exception("为 ShoveWebPart 设置 SiteID 失败，原因是 _Site 没有实例化到具体的站点数据上");
        }

        SiteID = _Site.ID;

        if (SiteID != 1)
        {
            SiteID = 0;
        }

        base.SetSiteID();
    }

    protected override void SetAllowDesign()
    {
        IsAllowDesign = false;

        string Url = Shove._Web.Utility.GetUrlWithoutHttp();
        Site Site = new Site()[Url];

        //取出从后台转入前台时，保存的数据(站点编号和会员编号)
        string Customer = Shove._Web.Session.GetSessionAsString(("Customer") + _Site.ID.ToString(), "");

        if (Customer != "")
        {
            DataTable dt = new DAL.Tables.tbl_Customer().Open("", "[CustomerTypeID] = 1 and ID=" + _Site.CustomerID, "");

            if (dt != null && dt.Rows.Count > 0)//存在赋予设计权限
            {
                if ((Site.CustomerID.ToString() == dt.Rows[0]["ID"].ToString())) 
                {
                    IsAllowDesign = true;
                }
            }
            else
            {
                IsAllowDesign = false;
            }
        }
        else
        {
            IsAllowDesign = false;
        }

        IsAllowDesign = false;

        base.SetAllowDesign();        
    }

    protected override void OnLoad(EventArgs e)
    {
        #region 获取站点ID

        _Site = new Site()[Shove._Web.Utility.GetUrlWithoutHttp()];

        if (_Site == null)
        {
            // 默认进入总公司网店
            Response.Redirect("~/Default.aspx");

            return;
        }
        else if (_Site.SiteStatus <= 0)          //站点是否停用
        {
            PublicFunction.GoError(ErrorNumber.NoData, "网店暂停使用，请联系管理员！", "Default");

            return;
        }

        #endregion

        base.OnLoad(e);
    }

}
